#include "alghelper.h"

algHelper::algHelper()
{
}

QString algHelper::cvtPointList2Text(QList<CvPoint> listPoint)
{
    QString listPointText;
    listPointText.append("{");
    foreach (CvPoint point, listPoint) {
        listPointText.append(QString("(%1,%2)").arg(point.x).arg(point.y));
    }
    listPointText.append("}");
    return listPointText;
}

QList<CvPoint> algHelper::cvtText2PointList(QString listPointText)
{
    QList<CvPoint> listPoint;
    if(listPointText.length() < 4)
        return listPoint;

    listPointText.remove('{');
    listPointText.remove('}');
    int pos;
    while(listPointText.length() > 0){
        if(listPointText.at(0) == '('){
            CvPoint point;
            listPointText.remove(0,1);
            pos = listPointText.indexOf(',');
            point.x = listPointText.left(pos).toInt();
            listPointText.remove(0, pos+1);
            pos = listPointText.indexOf(')');
            point.y = listPointText.left(pos).toInt();
            listPointText.remove(0,pos+1);

            listPoint.append(point);
        }
    }

    return listPoint;
}

QString algHelper::cvtEVideoSourceType2String(IVS::eVideoSourceType vsType)
{
    switch (vsType){
    case IVS::LocalFile:
        return QString("Local File");
    case IVS::Stream:
        return QString("Stream");
    case IVS::LocalCAM:
        return QString("Local Camera");
    case IVS::InvalidVideoSource:
        return QString("Invalid video source");
    default:
        return QString("Invalid video source");
    }
}

IVS::eVideoSourceType algHelper::cvtIndex2eVideoSourceType(int e)
{
    switch(e){
    case -1:
        return IVS::InvalidVideoSource;
    case 0:
        return IVS::LocalFile;
    case 1:
        return IVS::Stream;
    case 2:
        return IVS::LocalCAM;
    default:
        return IVS::InvalidVideoSource;
    }
}
